package myschool.service;

import myschool.dao.ExamDao;
import myschool.dao.GradeDao;
import myschool.entity.ExamResult;
import myschool.entity.Grade;
import myschool.entity.Page;
import myschool.util.MybatisUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class ExamService {
    public static final ExamService ME=new ExamService();

    public static final Logger Log = LoggerFactory.getLogger(ExamService.class);


    public Page<ExamResult> page(int pageNo ,   int pageSize,   Long stuno,  String subjectname,   Date start,  Date end) {
        SqlSession session = MybatisUtil.get();
        try {
            ExamDao dao = session.getMapper(ExamDao.class);
            List<ExamResult> list = dao.find(pageNo, pageSize, stuno, subjectname, start, end);
            int total=dao.findTotal(stuno, subjectname, start, end);
            return new Page<>(list,pageNo,total,pageSize);
        } finally {
            MybatisUtil.close(session);
        }
    }

    public Grade get(Long id) {
        SqlSession session = MybatisUtil.get();
        try {
            GradeDao dao = session.getMapper(GradeDao.class);
            return dao.get(id);
        } finally {
            MybatisUtil.close(session);
        }
    }


//
//    public int findTotal() {
//        SqlSession session = MybatisUtil.get();
//        try {
//            SubjectDao dao = session.getMapper(SubjectDao.class);
//            return dao.findTotal();
//        } finally {
//            MybatisUtil.close(session);
//        }
//    }

}
